/// 页面状态类型
enum ViewState {
  idle, //空闲
  busy, //加载中
  empty, //无数据
  error, //加载失败
}

/// 错误类型
enum ViewStateErrorType {
  httpException, //http异常，当http != 200
  unknowException, //未知异常
  cancelException, //请求被取消
  networkException, //网络异常
  fetchDataException, //其他异常
  unAuthorizedException, // 未认证
}

class ViewStateError {
  final ViewStateErrorType _errorType;
  String message;
  String errorMessage;

  ViewStateError(this._errorType,
      {required this.message, required this.errorMessage});

  ViewStateErrorType get errorType => _errorType;

  /// 以下变量是为了代码书写方便,加入的get方法.严格意义上讲,并不严谨
  bool get isHttpException => _errorType == ViewStateErrorType.httpException;
  bool get isUnknowException =>
      _errorType == ViewStateErrorType.unknowException;
  bool get isCancelException =>
      _errorType == ViewStateErrorType.cancelException;
  bool get isNetworkException =>
      _errorType == ViewStateErrorType.networkException;
  bool get isFetchDataException =>
      _errorType == ViewStateErrorType.fetchDataException;
  bool get isUnAuthorizedException =>
      _errorType == ViewStateErrorType.unAuthorizedException;

  @override
  String toString() {
    return 'ViewStateError{errorType: $_errorType, message: $message, errorMessage: $errorMessage}';
  }
}

enum ConnectivityStatus { wiFi, cellular, offline }
